﻿using System.Linq;
using System.Linq.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Entropy.Ext.Test
{
    [TestClass]
    public class InterfaceFactoryTest
    {
        [TestMethod]
        public void that_propertySet_goes_to_ast()
        {
            ISyntaxTree tree = new SyntaxTree();
            var ext = ExtFactoryProxy.Create(null, tree, null);
            ext.CreateGridPanel().beforeedit = null;
	        var nodes = tree.Result();
	        Assert.AreEqual(1, nodes); 
            var propertySet = (MemberExpression)nodes.First();
            Assert.AreEqual("beforeedit", propertySet.Member.Name);
	        var const_ = (ConstantExpression) propertySet.Expression;
	        Assert.IsNotNull(const_);
            Assert.IsNull(const_.Value);
        }

		[TestMethod]
        public void TestPropertySetWithExpressionOfDelegate()
        {
            ISyntaxTree tree = new SyntaxTree();
            var ext = ExtFactoryProxy.Create(null, tree, null);

	
			Expression<GridBeforeEdit> beforeedit = (e, eOpt, editor) => !(e.colIdx == 0 && e.record.get("id") != (object)0);
			ext.CreateGridPanel().beforeedit = beforeedit;
        }

    }
}
